package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-26 00:08
 **/
public class LeetCode2016 {

    public int maximumDifference(int[] nums) {
        int n = nums.length;
        int res = -1;
        int pre = nums[0];
        for (int i = 1; i < n; i++) {
            if (nums[i] > pre) {
                res = Math.max(res, nums[i] - pre);
            } else {
                pre = nums[i];
            }
        }
        return res;
    }

    //暴力
    /*public int maximumDifference(int[] nums) {
        int n = nums.length;
        int res = Integer.MIN_VALUE;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; ++ j) {
                int num = nums[j] - nums[i];
                res = num > 0 ? Math.max(num, res) : res;
            }
        }
        return res == Integer.MIN_VALUE ? -1 : res;
    }*/

}
